package com.mql.onlinechatsystem.system.controller;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.mql.onlinechatsystem.system.entity.SysUser;
import com.mql.onlinechatsystem.system.service.ISysUserService;
import com.mql.onlinechatsystem.system.vo.NewFriendVo;
import com.mql.onlinechatsystem.system.vo.TbUserrelationVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 马庆林
 * @since 2023-03-07
 */
@Api(tags = "用户接口")
@RestController
@RequestMapping("/system/sysUser")
@CrossOrigin
@Slf4j
public class SysUserController {
    @Autowired
    private ISysUserService iSysUserService;
    @ApiOperation("用户登录")
    @PostMapping(value = "/login")
    public JSONObject login(@RequestBody SysUser sysUser){
        JSONObject result=new JSONObject();
        SysUser iSysUserServiceOne = iSysUserService.getOne(new QueryWrapper<SysUser>().eq("username", sysUser.getUsername())
                .eq("password", sysUser.getPassword()));
        if (iSysUserServiceOne == null) {
            result.put("code",1001);
            result.put("message","用户名或者账号错误，请检查！");
            result.put("data",null);
        }else {
            result.put("code",200);
            result.put("message","登陆成功！");
            result.put("data",iSysUserServiceOne);
        }
        return result;
    }
    @GetMapping("/getUserLikeUserName")
    public JSONObject getUserLikeUserName(TbUserrelationVo tbUserrelationVo){
        JSONObject result=new JSONObject();
        List<NewFriendVo> newFriendVos=iSysUserService.getNewFriend(tbUserrelationVo);
        result.put("code",200);
        result.put("message","查询成功！");
        result.put("data",newFriendVos);
        return result;
    }
}
